# -*- coding: utf_8 -*-
# @Create   : 2021/8/20 9:18
# @Author   : yh
# @Remark   : 配置管理view层

from mxsoftpy import View
from server.common.VideoManage.VideoQuality.conf import *


class ConfView(View):
    """基础view"""

    def __init__(self, c_fk, server_c, request):
        """
        :param c_fk: 在数据库中的健名 --> str
        :param server_c: 执行的Server类 --> object
        :param request: request请求
        """
        self.c_fk = c_fk
        self.server_c = server_c(c_fk)
        super().__init__(request)


class ConfList(ConfView):
    def post(self):
        """
        获取全部数据
        :return: 返回结果
        """
        return '获取成功', self.server_c.list()


class ConfAdd(ConfView):
    def post(self):
        """
        添加单条数据
        params: 获取请求参数
        return: 成功返回添加成功的数据code
        """
        params = self.request.POST
        if not params.get('code') and params.get('name'):
            """ 需要不传code，但要传name,否则不执行 """
            ret = '添加成功', {f'{self.c_fk}_code': self.server_c.add(**params)}
        else:
            ret = '操作失败，数据值不对'
        return ret


class ConfUpdate(ConfView):
    def post(self):
        """
        更新数据的方法
        params: 获取请求参数
        return: 成功data为空
        """
        params = self.request.POST
        if params.get('code') and ('name' in params.keys()):
            """ 获取code和name，没有则不执行 """
            ret = '更新成功', self.server_c.update(**params)
        else:
            ret = '操作失败，数据值不对'
        return ret


class ConfDelete(ConfView):
    def post(self):
        """
        删除(关闭)数据的方法
        params: 获取请求参数
        return: 成功data为空
        """
        params = self.request.POST
        if params.get('code'):
            """ 获取code，没有则不执行 """
            ret = '删除成功', self.server_c.delete(params['code'])
        else:
            ret = '操作失败，数据值不对'
        return ret


class ConfRetrieve(ConfView):
    pass


# 设备类型
class DeviceTypeShare:
    """设备类型公共属性"""

    def __init__(self, request):
        """
        :param request: request请求
        自己在数据库中的健名: DeviceType
        自己指定的Server方法: VideoDeviceServer

        super() 会把值传给 VideoConfView 类
        """
        self.c_fk = 'DeviceType'
        self.server_c = VideoDeviceServer
        super().__init__(self.c_fk, self.server_c, request)


class DeviceTypeAdd(DeviceTypeShare, ConfAdd):
    """添加设备类型 """
    pass


class DeviceTypeList(DeviceTypeShare, ConfList):
    """获取设备类型"""
    pass


class DeviceTypeUpdate(DeviceTypeShare, ConfUpdate):
    """更新设备类型"""
    pass


class DeviceTypeDelete(DeviceTypeShare, ConfDelete):
    """删除设备类型 方法"""
    pass


# 码流
class StreamShare:
    """码流公共属性"""

    def __init__(self, request):
        """
        :param request: request请求
        自己在数据库中的健名: Stream
        自己指定的Server方法: StreamServer

        super() 会把值传给 VideoConfView 类
        """
        self.c_fk = 'Stream'
        self.server_c = StreamServer
        super().__init__(self.c_fk, self.server_c, request)


class StreamAdd(StreamShare, ConfAdd):
    """新增码流"""
    pass


class StreamList(StreamShare, ConfList):
    """获取码流"""
    pass


class StreamUpdate(StreamShare, ConfUpdate):
    """更新码流"""
    pass


class StreamDelete(StreamShare, ConfDelete):
    """删除码流"""
    pass


# 分辨率
class ResolutionShare:
    """分辨率公共属性"""

    def __init__(self, request):
        """
        :param request: request请求
        自己在数据库中的健名: Resolution
        自己指定的Server方法: ResolutionServer

        super() 会把值传给 VideoConfView 类
        """
        self.c_fk = 'Resolution'
        self.server_c = ResolutionServer
        super().__init__(self.c_fk, self.server_c, request)


class ResolutionAdd(ResolutionShare, ConfAdd):
    """添加分辨率"""
    pass


class ResolutionList(ResolutionShare, ConfList):
    """获取分辨率"""
    pass


class ResolutionUpdate(ResolutionShare, ConfUpdate):
    """更新分辨率"""
    pass


class ResolutionDelete(ResolutionShare, ConfDelete):
    """删除分辨率"""
    pass


# 任务周期
class TaskCycleShare:
    """任务周期公共属性"""

    def __init__(self, request):
        """
        :param request: request请求
        自己在数据库中的健名: TaskCycle
        自己指定的Server方法: TaskCycleTypeServer

        super() 会把值传给 VideoConfView 类
        """
        self.c_fk = 'TaskCycle'
        self.server_c = TaskCycleServer
        super().__init__(self.c_fk, self.server_c, request)


class TaskCycleAdd(TaskCycleShare, ConfAdd):
    """添加任务周期"""
    pass


class TaskCycleList(TaskCycleShare, ConfList):
    """获取任务周期"""
    pass


class TaskCycleUpdate(TaskCycleShare, ConfUpdate):
    """更新任务周期"""
    pass


class TaskCycleDelete(TaskCycleShare, ConfDelete):
    """删除任务周期"""
    pass


class TestItemsShare:
    """检测项目类型公共属性"""

    def __init__(self, request):
        """
        :param request: request请求
        自己在数据库中的健名: TestItems
        自己指定的Server方法: TestItemsServer

        super() 会把值传给 VideoConfView 类
        """
        self.c_fk = 'TestItems'

        self.server_c = TestItemsServer
        # """判断是否需要置信度类型"""
        # if request.POST.get('test_type'):
        #     self.server_c = TestItemsNOServer
        # else:
        #     self.server_c = TestItemsServer
        super().__init__(self.c_fk, self.server_c, request)


class TestItemsAdd(TestItemsShare, ConfAdd):
    """添加检测项目类型"""
    pass


class TestItemsList(TestItemsShare, ConfList):
    """获取检测项目类型"""
    pass


class TestItemsUpdate(TestItemsShare, ConfUpdate):
    """更新检测项目类型"""
    pass


class TestItemsDelete(TestItemsShare, ConfDelete):
    """删除检测项目类型"""
    pass
